<template>
    <div>
        <el-dialog title="编辑会员" :visible.sync="isShow" center :before-close="cancel">
            <el-form :model="memberForm"  :rules="rules" ref="memRef" >
                <el-form-item label="手机号" :label-width="formLabelWidth" prop="phone">
                    <el-input v-model="memberForm.phone" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="昵称" :label-width="formLabelWidth" prop="nickname">
                    <el-input v-model="memberForm.nickname" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码" :label-width="formLabelWidth">
                    <el-input v-model="memberForm.password" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="状态" :label-width="formLabelWidth">
                    <el-switch v-model="memberForm.status" active-color="#13ce66" inactive-color="#ff4949" :active-value="1"
                        :inactive-value="2">
                    </el-switch>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="confirm">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import {memberedit,memberinfo} from '../../request/api'
export default {
    props: ['isShow'],
    data() {
        return {
            memberForm: {
                nickname: '',//昵称
                phone: "",//手机号
                password: '',//密码
                status: 1,//状态1正常2禁用
            },
            formLabelWidth: '100px',
            rules: {
                nickname: [
                    { required: true, message: '请输入活动名称', trigger: 'blur' },
                    { min: 1, max: 5, message: '长度在 1 到 5 个字符', trigger: 'blur' }
                ],
                phone: [
                    { required: true, message: '请输入活动名称', trigger: 'blur' },
                    { min: 11, max: 11, message: '长度在 11 到 11 个字符', trigger: 'blur' }
                ],
            }

        }
    },
    methods: {
        cancel() {
            this.$emit('cancel',false)
            this.reset()
        },
        reset(){
            this.memberForm={
                nickname: '',//昵称
                phone: "",//手机号
                password: '',//密码
                status: 1,//状态1正常2禁用
            }
        },
        confirm(){
            this.$refs.memRef.validate((val)=>{
                if(val){
                    memberedit(this.memberForm)
                    .then(res=>{
                        if(res.code==200){
                            this.$message.success(res.msg)
                            this.$store.dispatch('member/GetMemberInfo')
                            this.cancel()
                        }else{
                            this.$message.error(res.msg)
                        }
                    })
                }
            })
        },
        async lookup(uid){
           let res = await memberinfo({uid})
           this.memberForm=res.list
           this.memberForm.uid = uid
        }
    },
    mounted() { },
    watch: {},
    computed: {},
    filters: {},
    components: {}
}
</script>
<style scoped></style>